# Maintainer: Caleb Maclennan <caleb@alerque.com>
# Contributor: Cirk2 <privat+aur at cirk2 dot de>

pkgbase=sdbus-cpp
pkgname=($pkgbase $pkgbase-doc)
pkgver=1.3.0
pkgrel=1
pkgdesc='a high-level C++ D-Bus library designed to provide expressive, easy-to-use API'
url="https://github.com/Kistler-Group/$pkgbase"
arch=(loong64 x86_64)
license=(LGPL2.1 'custom:sdbus-c++ LGPL Exception 1.0')
depends=(expat
         systemd-libs)
makedepends=(cmake
             doxygen
             systemd)
_archive="$pkgbase-$pkgver"
source=("$url/archive/v$pkgver/$_archive.tar.gz")
sha256sums=('d44f59abdd64d8f1ca3af7db58bc6518cb081fc9ff16285c3d75a68f5c073d10')

build() {
	cmake -B build -S "$_archive" \
		-D CMAKE_INSTALL_PREFIX=/ \
		-D CMAKE_BUILD_TYPE=Release \
		-D BUILD_CODE_GEN=ON \
		-D BUILD_DOXYGEN_DOC=ON
	cmake --build build
	cmake --build build --target doc

	# Install so we can split the packaging up later
	DESTDIR="fakeinstall" cmake --install build

	# Remove references to $srcdir
	find fakeinstall/usr/share/doc \
		-name \*.html \
		-print \
		-exec sed \
		  -e "s|$srcdir/sdbus-cpp/include|/usr/include|g" \
		  -e "s|$srcdir/sdbus-cpp||" \
		  -i {} \;
}

package_sdbus-cpp() {
	install -Dm0644 -t "$pkgdir/usr/share/licenses/$pkgbase/" "$_archive/COPYING"*
	for dir in lib include bin; do
		_package_dir $dir
	done
}

package_sdbus-cpp-doc() {
	_package_dir share/doc
}

_package_dir() {
	install -dm755 "$pkgdir/usr/$1"
	cp -dr --no-preserve=owner "$srcdir/fakeinstall/usr/$1/"* "$pkgdir/usr/$1"
}
